package com.h1909d.weinfo.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.h1909d.weinfo.R;
import com.h1909d.weinfo.bean.ArticleBean;

import java.util.ArrayList;
import java.util.List;

public class RlvJsoupAdapter extends RecyclerView.Adapter<RlvJsoupAdapter.ViewHolder> {
    
    private Context context;
    private List<ArticleBean> articleBeans=new ArrayList<>();

    public RlvJsoupAdapter(Context context) {
        this.context = context;
    }

    public void RlvJsoupAdapter(List<ArticleBean> articleBeans) {
        this.articleBeans.addAll(articleBeans);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_jsoup, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ArticleBean articleBean = articleBeans.get(position);
        holder.mTv.setText(articleBean.author);
    }

    @Override
    public int getItemCount() {

        return articleBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView mTv;

        public ViewHolder(View itemView) {
            super(itemView);

            mTv = itemView.findViewById(R.id.item_jsoup_tv);

        }
    }
}
